$(function () {
    $('#modify-btn').on('tap', function () {
        var oldPassword = $('[name=originPass]').val().trim();
        var newPassword = $('[name=newPass]').val().trim();
        var confrimNewPass = $('[name=confrimNewPass]').val().trim();
        var vCode = $('[name=vCode]').val().trim();
        if (!oldPassword) {
            mui.toast('请输入原密码')
            return;
        }
        if (!newPassword || !confrimNewPass) {
            mui.toast('请输入密码')
            return
        }
        if (newPassword != confrimNewPass) {
            mui.toast('密码不一致，请重新输入')
            return
        }
        $.ajax({
            type: "post",
            url: "/user/updatePassword",
            data: {
                oldPassword,
                newPassword,
                vCode
            },
            success: function (res) {
                console.log(res);
                if (res.success) {
                    mui.toast('修改成功，请重新登录')
                    location.href = 'login.html'
                }
            }
        });

    })
    //获取验证码
    $('#getCode').on('tap', function () {
        $.ajax({
            type: "get",
            url: "/user/vCodeForUpdatePassword",
            success: function (res) {
                console.log(res);
                $('#getCode').text(res.vCode)
            }
        });
    })
})